Ext.define('Sh.ux.EchartPanel', {
    extend: 'Ext.panel.Panel',
    alias : 'widget.echartpanel',
    config: {
    	option: undefined,
    	dataUrl: '',
    	chart: undefined,
    	autoRender: false,
    	params: undefined
    },
	constructor : function(config){
		this.setParams(config.params);
		this.callParent([config]);
	},
	initComponent : function() {
		var me = this;
		me.on('boxready',function(){
			var myChart = echarts.init(me.body.dom[0]);
			me.setChart(myChart);
			if(me.autoRender){
				me.update(me.getParams());
			}
		});
		me.callParent();
	},
	update: function(params){
		var me = this;
		var myMask = new Ext.LoadMask(me, {msg:"正在加载数据..."});
		myMask.show();
		me.setParams(params);
		var myChart = echarts.init(me.body.dom);
		me.setChart(myChart);
		Ext.Ajax.request({
		    url: me.dataUrl,
		    params: params||{},
		    success: function(response){
    	    	var rs = Ext.decode(response.responseText);
    	    	if(myChart){
    	    		myChart.setOption(rs);
    	    	}
    	    	
    	    	myMask.hide();
		    }
		});
	},
	downLoad: function(title){
		var me = this;
		downLoad('export/exportEchart.do',{title: title,data: me.getChart().getDataURL()});
	}
});